package cn.njyd.corejava.thread.myday03;

public class DeadThreadDemo01 {
    public static void main(String[] args) {
        Object lockA = new Object(),lockB = new Object();
        Thread t1 = new Thread(()->{
            synchronized (lockA) {
                System.out.println(Thread.currentThread().getName()+"持有一只筷子");
                synchronized (lockB) {
                    System.out.println(Thread.currentThread().getName()+"成功获取对方筷子");
                }
            }
        },"用户A");
        Thread t2 = new Thread(()->{
            synchronized (lockB) {
                System.out.println(Thread.currentThread().getName()+"持有一只筷子");
                synchronized (lockA) {
                    System.out.println(Thread.currentThread().getName()+"成功获取对方筷子");
                }
            }
        },"用户B");
        t1.start();
        t2.start();
    }

}
